#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: conftest.py.py 
@version:
@time: 2021/07/29 
"""
import os, sys
import pytest
from TapClientCore.T01_init_conf.v2_init.init_config import MFA, useage, serve_collection

sys.path.append(os.getcwd())


def pytest_addoption(parser):
    parser.addoption(
        "--serve",
        action="store",
        default="http://test.cloud.tapdata.net",
        help="设置被测服务地址"
    )
    parser.addoption(
        "--apiserve",
        action="store",
        default="http://192.168.1.132:31205",
        help="设置被测apiserve服务地址"
    )
    parser.addoption(
        "--jenkinsEnv",
        action="store",
        default="local",
        help="设置jenkins服务，local为公司本地环境，cloud为云环境"
    )


@pytest.fixture(scope='session')
def v2_serve(request):
    serve_config = request.config.getoption("--serve")
    MFA.update(serve_collection, useage, {"$set": {"serve": serve_config}})
    MFA.close()
    return serve_config


@pytest.fixture(scope='session')
def v2_apiserve(request):
    serve_config = request.config.getoption("--apiserve")
    MFA.update(serve_collection, useage, {"$set": {"apiserve": serve_config}})
    MFA.close()
    return serve_config


@pytest.fixture(scope='session')
def v2_jenkinsEnv(request):
    serve_config = request.config.getoption("--jenkinsEnv")
    MFA.update(serve_collection, useage, {"$set": {"jenkinsEnv": serve_config}})
    MFA.close()
    return serve_config
